package com.mida.dms.knw.controller;

import com.mida.dms.knw.entity.KnwCommonWordsTree;
import com.mida.dms.knw.entity.vo.KnwConceptualVo;
import com.mida.dms.knw.service.KnwCommonWordsTreeService;
import com.mida.dms.knw.vo.CommonWordsTreeDto;
import com.mida.dms.knw.vo.CommonWordsTreeVo;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import io.swagger.annotations.Api;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: zangjian
 * @Description:
 * @Date: 2021/6/28 17:09
 * @params:
 */
@RestController
@RequestMapping("/knwCommonWordsTree")
@Api(tags = "常用语模板")
@Slf4j
@CrossOrigin
public class KnwCommonWordsTreeController {
    @Autowired
    private KnwCommonWordsTreeService knwCommonWordsTreeService;
    /**
     * 1、新增常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/addCommonWordsTree",consumes = {"application/json"})
    public ActionResult addCommonWordsTree(@RequestBody CommonWordsTreeVo commonWordsTreeVo) {
        ActionResult result = new ActionResult();
        try {
        return knwCommonWordsTreeService.addCommonWordsTree(commonWordsTreeVo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            result.setMessage("新增常用语失败");
            return result;
        }
    }

    /**
     * 2、删除常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/deleteCommonWordsTree",consumes = {"application/json"})
    public ActionResult deleteCommonWordsTree(@RequestBody CommonWordsTreeVo commonWordsTreeVo) {

        ActionResult result = new ActionResult();
        try {
            return knwCommonWordsTreeService.deleteCommonWordsTree(commonWordsTreeVo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            result.setMessage("删除常用语失败");
            return result;
        }
    }
    /**
     * 3、修改常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/updateCommonWordsTree",consumes = {"application/json"})
    public ActionResult updateCommonWordsTree(@RequestBody CommonWordsTreeVo commonWordsTreeVo) {
        ActionResult result = new ActionResult();
        try {
        return knwCommonWordsTreeService.updateCommonWordsTree(commonWordsTreeVo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            result.setMessage("修改常用语失败");
            return result;
        }
    }


    /**
     * 4.1、查询个人树形常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/selectCommonWordsTrees",consumes = {"application/json"})
    public ListResult<List<CommonWordsTreeVo>> selectCommonWordsTrees(@RequestBody CommonWordsTreeVo commonWordsTreeVo) {
        ListResult<List<CommonWordsTreeVo>> listListResult = new ListResult<>();
        try {
            return knwCommonWordsTreeService.selectCommonWordsTrees(commonWordsTreeVo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            listListResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            listListResult.setMessage("查询常用语失败");
            return listListResult;
        }
    }

    /**
     * 5、排序常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/sortCommonWordsTree",consumes = {"application/json"})
    public ActionResult sortCommonWordsTree(@RequestBody List<KnwCommonWordsTree> commonWordsTreeSoids) {
        ActionResult result = new ActionResult();
        try {
        return knwCommonWordsTreeService.sortCommonWordsTree(commonWordsTreeSoids);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            result.setMessage("排序常用语失败");
            return result;
        }
    }

    /**
     * 6、查询常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/getCommonWordsTree", consumes ={"application/json"})
    ListResult<List<CommonWordsTreeVo>> getCommonWordsTree(@RequestBody CommonWordsTreeVo commonWordsTreeVo) {
        ListResult<List<CommonWordsTreeVo>> listListResult = new ListResult<>();
        try {
            return knwCommonWordsTreeService.getCommonWordsTree(commonWordsTreeVo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            listListResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            listListResult.setMessage("查询常用语失败");
            return listListResult;
        }
    }

    /**
     * 7.1、分享和取消分享常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/shareCommonWordsTrees", consumes = {"application/json"})
    public ActionResult shareCommonWordsTrees(@RequestBody CommonWordsTreeVo commonWordsTreeVo) {
        ActionResult result = new ActionResult();
        try {
            return knwCommonWordsTreeService.shareCommonWordsTrees(commonWordsTreeVo);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            result.setMessage("分享常用语失败");
            return result;
        }
    }



    /**
     * 2、查询删除节点下是否有常用语
     *
     * @param
     * @return
     */
    @PostMapping(value = "/isDelete",consumes = {"application/json"})
    public Integer isDelete(@RequestBody CommonWordsTreeVo commonWordsTreeVo){

        return knwCommonWordsTreeService.isDelete(commonWordsTreeVo);
    }
}
